package org.attached.user.service;

import org.attached.user.config.RedisConfig;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


@Service
public class RedisService implements InitializingBean {
	
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	@Autowired
	private RedisConfig redisConfig;

	@Override
	public void afterPropertiesSet() throws Exception {
		redisConfig.valueOperations(redisTemplate);
	}
	
	public void setValueOperations(String key, String value) {
		redisConfig.valueOperations(redisTemplate).set(key, value);
	}
	
	public String getValueOperations(String key) {
		return (String) redisConfig.valueOperations(redisTemplate).get(key);
	}
	
	public boolean hasKeyValueOperations(String key) {
		return redisTemplate.hasKey(key);
	}
	
	public void deleteKeyValueOperations(String key) {
		redisTemplate.delete(key);
	}
}
